#include <vector>

using namespace std;


/**
 * @brief 303. 区域和检索 - 数组不可变
 * https://leetcode.cn/problems/range-sum-query-immutable/
 */
class NumArray {
private:
    vector<int> sums;

public:
    NumArray(vector<int>& nums) {
        int n = nums.size();
        sums.resize(n+1);
        sums[0] = 0;
        for (int i=0; i<n; i++) {
            sums[i+1] = sums[i] + nums[i];
        }
    }
    
    int sumRange(int left, int right) {
        return sums[right+1] - sums[left];
    }
};

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray* obj = new NumArray(nums);
 * int param_1 = obj->sumRange(left,right);
 */
